package top.zhangjianyong.test.entity;

import org.apache.commons.collections4.CollectionUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class People {

    private int winTime;

    private int defultA;
    private int defultB;
    private int income;
    private String name;
    List<Coin> list ;

    public People(String name,int a,int b) {
        this.name = name;
        this.defultA=a;
        this.defultB=b;

        init();

    }

    public  void  init (){
        list=new ArrayList<Coin>();
        for (int i=0;i<this.defultA ;i++){
            list.add(new Coin(true));
        }
        for (int i=0;i<this.defultB;i++){
            list.add(new Coin(false));
        }
        Collections.shuffle(list);
    }

    public boolean hasNextCoin(){
        if (CollectionUtils.isEmpty(list))
            return false;
        return list.size()>0;
    }

    public Coin nextCoin(){
        if (!hasNextCoin())
            return null;
        Coin coin =list.get(0);
        list.remove(0);
        Collections.shuffle(list);
        return coin;
    }

    public int getWinTime() {
        return winTime;
    }

    public void setWinTime(int winTime) {
        this.winTime = winTime;
    }

    public List<Coin> getList() {
        return list;
    }

    public void setList(List<Coin> list) {
        this.list = list;
    }

    public int getIncome() {
        return income;
    }

    public void setIncome(int income) {
        this.income = income;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void addToIncome(int i) {

        this.income += i;

    }

    @Override
    public String toString() {
        return "People{" +
                "winTime=" + winTime +
                ", income=" + income +
                ", name='" + name + '\'' +
                '}';
    }

    public void win() {
        this.winTime++;
    }
}
